<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/11/18
  Time: 14:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>OA系统登录界面</title>
    <link href="#" rel="shortcut icon">
    <link rel="stylesheet" href="static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="static/layuiadmin/style/admin.css" media="all">
    <script src="static/layuiadmin/layui/layui.js" type="text/javascript"></script>
    <script src="static/js/jquery-3.1.1.min.js" type="text/javascript"></script>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <title>登录界面</title>
    <link href="static/css/default.css" rel="stylesheet" type="text/css"/>
    <!--必要样式-->
    <link href="static/css/styles.css" rel="stylesheet" type="text/css"/>
    <link href="static/css/demo.css" rel="stylesheet" type="text/css"/>
    <link href="static/css/loaders.css" rel="stylesheet" type="text/css"/>
    <style>
        body .login_fields__submit {
            position: relative;
            top: 17px;
            left: 65px;
            width: 80%;
            right: 0;
            margin: auto;
        }
    </style>
</head>
<body>
<div class='login'>
    <div class='login_title'>
        <span>管理员登录</span>
    </div>
    <div class='login_fields'>
        <form action="/login" method="post">
            <div class='login_fields__user'>
                <div class='icon'>
                    <img alt="" src='static/img/user_icon_copy.png'>
                </div>
                <input id="username" name="username" placeholder='用户名' maxlength="16" type='text'
                       value=""/>
                <div class='validation'>
                    <img alt="" src='static/img/tick.png'>
                </div>
            </div>
            <div class='login_fields__password'>
                <div class='icon'>
                    <img alt="" src='static/img/lock_icon_copy.png'>
                </div>
                <input id="password" name="password" placeholder='密码' maxlength="16" type='password'>
                <div class='validation'>
                    <img alt="" src='static/img/tick.png'>
                </div>
            </div>
            <div class='login_fields__password'>
                <div class='icon'>
                    <img alt="" src='static/img/key.png'>
                </div>
                <input id="code" name="code" placeholder='验证码' maxlength="4" type='text' name="ValidateNum"
                       autocomplete="off">
                <div class='validation' style="opacity: 1; right: -85px;top: -3px;">
                    <canvas class="J_codeimg" id="myCanvas" onclick="Code();">对不起，您的浏览器不支持canvas，请下载最新版浏览器!</canvas>
                </div>
            </div>
            <div class='login_fields__submit'>
                <input id="sub" type='button' onclick="subm()" value='登录'>
                <%--<button onclick="aefaf()">sss</button>--%>
                <div style="margin-left: 0px">
                    <input id="aefaf" type='button' value='注册'>
                </div>

            </div>
        </form>
    </div>
    <div class='success'>
    </div>
    <div class='disclaimer'>
        <p>欢迎登陆后台管理系统</p>
    </div>
</div>
<div class='authent'>
    <div class="loader" style="height: 44px;width: 44px;margin-left: 28px;">
        <div class="loader-inner ball-clip-rotate-multiple">
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
    <p>认证中...</p>
</div>
<div class="OverWindows"></div>
<link href="static/layui/css/layui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="static/js/jquery.min.js"></script>
<script type="text/javascript" src="static/js/jquery-ui.min.js"></script>
<script type="text/javascript" src='static/js/stopExecutionOnTimeout.js?t=1'></script>
<script src="static/layui/layui.js" type="text/javascript"></script>
<script src="static/js/Particleground.js" type="text/javascript"></script>
<script src="static/js/Treatment.js" type="text/javascript"></script>
<script src="static/js/jquery.mockjax.js" type="text/javascript"></script>
<script type="text/javascript">
    var canGetCookie = 0;//是否支持存储Cookie 0 不支持 1 支持
    var ajaxmockjax = 1;//是否启用虚拟Ajax的请求响 0 不启用  1 启用
    //默认账号密码
    var truelogin = "";
    var truepwd = "";

    $("#aefaf").click(function () {
        window.location.href = "register";
    });

    function subm() {
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;

            if ($('#username').val() == "") {
                layer.msg("请输入用户名！");
            } else if ($('#password').val() == "") {
                layer.msg("请输入密码！");
            } else if ($('#code').val() == "") {
                layer.msg("请输入验证码！");
            } else if ($('#code').val() != CodeVal) {
                layer.msg("验证码错误！");
                Code();
            } else {
                let people = JSON.stringify({
                    username: $('#username').val(),
                    password: $('#password').val()
                });
                $.ajax({
                    url: 'doLogin',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        people: people
                    },
                    success: function (rtn) {
                        console.log(rtn);
                        if (rtn.code == 1) {
                            window.location.href = "success";
                        } else {
                            layer.msg(rtn.msg);
                            Code();
                        }
                    }
                });
            }
        });
    }

    var CodeVal = 0;
    Code();

    function Code() {
        if (canGetCookie == 1) {
            createCode("AdminCode");
            var AdminCode = getCookieValue("AdminCode");
            showCheck(AdminCode);
        } else {
            showCheck(createCode(""));
        }
    }

    function showCheck(a) {
        CodeVal = a;
        var c = document.getElementById("myCanvas");
        var ctx = c.getContext("2d");
        ctx.clearRect(0, 0, 1000, 1000);
        ctx.font = "80px 'Hiragino Sans GB'";
        ctx.fillStyle = "#E8DFE8";
        ctx.fillText(a, 0, 100);
    }

    $(document).keypress(function (e) {
        // 回车键事件
        if (e.which == 13) {
            $('input[type="button"]').click();
        }
    });
    //粒子背景特效
    $('body').particleground({
        dotColor: '#E8DFE8',
        lineColor: '#133b88'
    });

</script>
</body>
</html>
